Skip to content

fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057

Open
jacekradko wants to merge 5 commits into
mainfrom
jacek/path-matcher-path-star
Open

fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057
jacekradko wants to merge 5 commits into
mainfrom
jacek/path-matcher-path-star

Conversation

@jacekradko

@jacekradko jacekradko commented Jul 1, 2026

Copy link
Copy Markdown
Member

createRouteMatcher's route-type suggestions now offer /dashboard/:path* instead of /dashboard(.*). (.*) also matches sibling routes like /dashboardxyz; :path* matches only /dashboard and its path-segment subtree. It's a type-level suggestion only (the param is Autocomplete-wrapped), so existing (.*) patterns keep type-checking and there's no runtime change.

The suggestion lives in a new WithPathSegmentWildcard type; the published WithPathPatternWildcard alias keeps its (.*) shape (now deprecated) so direct importers of @clerk/shared/pathMatcher don't break on a patch. break-check flagged an earlier in-place rewrite of that alias as a major for exactly that reason.

Worth a look: the root special-case. WithPathSegmentWildcard<'/'> resolves to /:path*, not the naive //:path* (which matches only / at runtime, not everything). I verified /dashboard/:path*, /:path*, and legacy (.*) against the vendored matcher, and @clerk/nextjs typechecks clean against it.

Scoped to the types on purpose: the ['/foo', '/bar(.*)'] JSDoc examples in nextjs/astro/nuxt are left as-is here and can be aligned in a follow-up. The docs are moving to recommend :path* too.

Summary by CodeRabbit

  • New Features
    • Route autocomplete suggestions now prefer the segment-aware :path* subtree wildcard syntax (e.g. /dashboard/:path*) for clearer, more accurate nested-path suggestions.
    • The legacy (.*) wildcard form remains supported, but autocomplete now favors the newer suggestion style.
  • Bug Fixes
    • Improved wildcard handling for the root path and trailing slashes to prevent incorrect suggestion shapes.
    • Type-level autocomplete output changes only; runtime route matching behavior is unchanged.

…ypes

WithPathPatternWildcard now suggests `/dashboard/:path*` instead of `/dashboard(.*)`.
The `:path*` form matches on path-segment boundaries, so it covers `/dashboard` and its
subtree without also matching sibling routes like `/dashboardxyz`. Root is special-cased
to `/:path*` to avoid a malformed `//:path*`. Backward compatible: the param is
Autocomplete-wrapped, so existing `(.*)` patterns still type-check, and there is no runtime change.
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0933300

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@clerk/shared Patch
@clerk/nextjs Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/electron Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/headless Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch
@clerk/swingset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jul 3, 2026 12:00am
swingset Ready Ready Preview, Comment Jul 3, 2026 12:00am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: d1401dc2-22c3-4718-b600-249d974ceb00

📥 Commits

Reviewing files that changed from the base of the PR and between 53a83be and 42aee20.

📒 Files selected for processing (1)
  • packages/shared/src/pathMatcher.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/pathMatcher.ts

📝 Walkthrough

Walkthrough

This PR changes route-pattern autocomplete types to prefer :path* subtree suggestions, updates the shared matcher types and Next.js route matcher typing to use the new wildcard, and adds a changeset describing the type-level output change.

Changes

Path wildcard type change

Layer / File(s) Summary
Wildcard type and matcher update
packages/shared/src/pathMatcher.ts, packages/nextjs/src/server/routeMatcher.ts, .changeset/path-matcher-segment-wildcard.md
WithPathSegmentWildcard is introduced, WithPathPatternWildcard is marked deprecated, PathPattern now uses the new wildcard, RouteMatcherParam picks up the new shared type, and the changeset records the autocomplete suggestion update.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

I hopped through routes with joy today,
:path* now leads the way.
Old (.*) still stays in sight,
But softer suggestions feel just right.
🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: path type suggestions now prefer the :path* subtree form in shared and nextjs route matchers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@9057

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@9057

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@9057

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@9057

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@9057

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@9057

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@9057

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@9057

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@9057

@clerk/express

npm i https://pkg.pr.new/@clerk/express@9057

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@9057

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@9057

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@9057

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@9057

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@9057

@clerk/react

npm i https://pkg.pr.new/@clerk/react@9057

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@9057

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@9057

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@9057

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@9057

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@9057

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@9057

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@9057

commit: 0933300

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-07-03T00:02:11.857Z

Summary

Metric Count
Packages analyzed 19
Packages with changes 1
🔴 Breaking changes 1
🟡 Non-breaking changes 0
🟢 Additions 1

Warning
1 breaking change(s) detected - Major version bump required

🤖 This report was reviewed by claude-sonnet-4-6 (partial).

Warning
AI review did not complete for 1 subpath (1 change); affected changes show rule-based (pessimistic) verdicts only and may be over-reported as breaking.

  • @clerk/shared (./pathMatcher): 1 change unreviewed (AI review did not complete (call failed, timed out, or returned an unusable response after retries))

🔴 Breaking changes index (1)

Every breaking change, up front. Full diffs are in the package sections below.

Package Subpath Change
@clerk/shared ./pathMatcher PathPattern

@clerk/shared

Current version: 4.23.0
Recommended bump: MAJOR → 5.0.0

Subpath ./pathMatcher

🔴 Breaking Changes (1)

Changed: PathPattern
- type PathPattern = Autocomplete<WithPathPatternWildcard>;
+ type PathPattern = Autocomplete<WithPathSegmentWildcard>;

Breaking change in type alias PathPattern: Type changed: import("@clerk/shared").~Autocomplete<import("@clerk/shared").WithPathPatternWildcard>import("@clerk/shared").~Autocomplete<import("@clerk/shared").WithPathSegmentWildcard>

🟢 Additions (1)

Added: WithPathSegmentWildcard
+ type WithPathSegmentWildcard<T = string> = T extends '/' ? '/:path*' : `${StripTrailingSlash<T & string>}/:path*`;

Added type alias WithPathSegmentWildcard


Report generated by Break Check

Last ran on 0933300.

@jacekradko jacekradko changed the title fix(shared): suggest :path* subtree form in createRouteMatcher path types fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types Jul 2, 2026
@github-actions github-actions Bot added the nextjs label Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/shared/src/pathMatcher.ts (1)

11-11: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Trailing-slash input produces a malformed double-slash suggestion.

For T = '/dashboard/', the non-root branch yields '/dashboard//:path*'. Root is special-cased but trailing slashes on other paths aren't, so the autocomplete suggestion could look malformed for such inputs. This is type-level only (no runtime impact via Autocomplete), but worth a quick look given the root case was already special-cased for the same class of problem.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/shared/src/pathMatcher.ts` at line 11, The WithPathSegmentWildcard
type in pathMatcher.ts only special-cases the root path, so trailing-slash
inputs like a non-root path ending in "/" can produce a malformed double-slash
suggestion. Update the type-level logic in WithPathSegmentWildcard to normalize
or strip a trailing slash before appending "/:path*", while preserving the
existing root-path special case. Keep the change confined to the path-matching
type aliases so Autocomplete continues to infer clean suggestions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/shared/src/pathMatcher.ts`:
- Around line 9-11: Add JSDoc to the public type WithPathSegmentWildcard in
pathMatcher so it is documented like the deprecated WithPathPatternWildcard and
included correctly in generated Clerk Docs. Replace the existing line comment
with a proper JSDoc block on the type alias, preserving the explanation about
the :path* subtree form and the special-case for '/'.

---

Nitpick comments:
In `@packages/shared/src/pathMatcher.ts`:
- Line 11: The WithPathSegmentWildcard type in pathMatcher.ts only special-cases
the root path, so trailing-slash inputs like a non-root path ending in "/" can
produce a malformed double-slash suggestion. Update the type-level logic in
WithPathSegmentWildcard to normalize or strip a trailing slash before appending
"/:path*", while preserving the existing root-path special case. Keep the change
confined to the path-matching type aliases so Autocomplete continues to infer
clean suggestions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ba2b7da-063e-4f9d-9681-bec17ba96bb4

📥 Commits

Reviewing files that changed from the base of the PR and between 42cecb9 and 53a83be.

📒 Files selected for processing (3)
  • .changeset/path-matcher-segment-wildcard.md
  • packages/nextjs/src/server/routeMatcher.ts
  • packages/shared/src/pathMatcher.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/path-matcher-segment-wildcard.md

Comment thread packages/shared/src/pathMatcher.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants